package com.cicc.beergamevirtualsimulationsystem.controller;

import com.cicc.beergamevirtualsimulationsystem.common.constant.RoomConstant;
import com.cicc.beergamevirtualsimulationsystem.common.errorEnum.RoomErrorEnum;
import com.cicc.beergamevirtualsimulationsystem.model.R;
import com.cicc.beergamevirtualsimulationsystem.model.parameter.dto.DefaultParameterDto;
import com.cicc.beergamevirtualsimulationsystem.model.parameter.dto.RoomParameterDto;
import com.cicc.beergamevirtualsimulationsystem.model.parameter.req.ParameterUpdateReq;
import com.cicc.beergamevirtualsimulationsystem.model.userType.RoleTypeParameterDto;
import com.cicc.beergamevirtualsimulationsystem.service.ParameterService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 配置游戏参数
 *
 * @author 银角大王
 */
@RestController
@RequestMapping("/api/parameter")
@RequiredArgsConstructor
public class ParameterController {

    private final ParameterService parameterService;


    /**
     * 查询系统默认参数
     *
     * @return
     */
    @GetMapping
    public R<DefaultParameterDto> queryDefaultParameter() {
        return R.ok(parameterService.queryDefaultParameter());
    }

    /**
     * 查询当前房间的配置参数
     *
     * @param roomId 房间id
     * @return
     */
    @GetMapping("/{roomId}")
    public R<RoomParameterDto> queryById(
            @NotEmpty(message = RoomConstant.ROOM_ID_ERROR) @PathVariable String roomId) {

        return R.ok(parameterService.queryParameterByRoomId(roomId));
    }

    /**
     * 更新房间配置
     */
    @PostMapping
    public R updateRoomParameter(@RequestBody ParameterUpdateReq parameterUpdateReq) {
        parameterService.updateRoomParameter(parameterUpdateReq);
        return R.ok();
    }
}
